package com.itheima.day13.service.impl;

import com.itheima.day13.aop.RateLimit;
import com.itheima.day13.pojo.Order;
import com.itheima.day13.pojo.UserInfo;
import com.itheima.day13.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Override
    @RateLimit(value = 10, timeWindow = 60) // 每分钟最多调用10次
    public UserInfo getUserInfo(String userId) {
        // 查询用户信息的逻辑
        System.out.println("success");
        System.out.println("Fetching user info for: " + userId);
        return new UserInfo(userId, "John Doe", "john.doe@example.com");
    }

    @Override
    @RateLimit(value = 5, timeWindow = 60) // 每分钟最多调用5次
    public List<Order> getUserOrders(String userId) {
        // 查询用户订单的逻辑
        System.out.println("Fetching orders for: " + userId);
        return Arrays.asList(new Order("order1"), new Order("order2"));
    }

    @Override
    public void updateUserInfo(String userId, UserInfo userInfo) {
        // 更新用户信息的逻辑
        System.out.println("Updating user info for: " + userId);
    }
}
